#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "SDL/SDL.h"

void apply_surface(double x, double y, SDL_Surface *source, SDL_Surface *destination)
{
        SDL_Rect offset;
        offset.x = x;
        offset.y = y;
        SDL_BlitSurface(source, NULL, destination, &offset);
}

char *double_to_string(double d, int decimal)
{
        decimal = decimal < 0 ? 0 : decimal;
        char *p;
        char dd[20];
        switch (decimal)
        {
        case 0:
                sprintf(dd, "%.0lf", d);
                break;
        case 1:
                sprintf(dd, "%.1lf", d);
                break;
        case 2:
                sprintf(dd, "%.2lf", d);
                break;
        case 3:
                sprintf(dd, "%.3lf", d);
                break;
        case 4:
                sprintf(dd, "%.4lf", d);
                break;
        case 5:
                sprintf(dd, "%.5lf", d);
                break;
        default:
                sprintf(dd, "%.6lf", d);
                break;
        }
        p = malloc(strlen(dd));
        strcpy(p, dd);
        return p;
}